﻿@using MudBlazor.Interfaces;

<MudStack>
    <MudDateRangePicker @ref="_picker" @bind-DateRange="@DateRange"
    MinDays="MinDays" MaxDays="@MaxDays"
    PickerVariant="PickerVariant.Static" Margin="Margin.Dense"
    IsDateDisabledFunc="@( (d) => AllowWeekends ? false : IsWeekend(d))" 
    AllowDisabledDatesInRange AllowDisabledDatesInCount="@CountDisabledDays"
    AdditionalDateClassesFunc="@((DateTime dt)=>((int)dt.DayOfWeek == 0 ? "red-text text-accent-4" : ""))" />

    <MudStack Row>
        <MudSwitch @bind-Value="AllowWeekends" @bind-Value:after="@(() => _picker.RecalculateValidDays())" Color="Color.Primary">Allow Weekends</MudSwitch>
        <MudSwitch @bind-Value="CountDisabledDays" Color="Color.Primary">Include Disabled</MudSwitch>
    </MudStack>

</MudStack>

@code {
    public static string __description__ = "DateTime range with a restricted mix & max days selection";
    
    private MudDateRangePicker? _picker;
    
    [Parameter]
    public DateRange? DateRange { get; set; }

    [Parameter]
    public int MinDays { get; set; } = 3;

    [Parameter]
    public int MaxDays { get; set; } = 7;

    [Parameter]
    public bool AllowWeekends { get; set; } = true;
    
    [Parameter]
    public bool CountDisabledDays { get; set; } = true;

    private static bool IsWeekend(DateTime date)
    {
        DayOfWeek day = date.DayOfWeek;
        return day == DayOfWeek.Saturday || day == DayOfWeek.Sunday;
    }
}